/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package myjme.tin.core;

import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import java.util.ArrayList;
import java.util.Random;

/**
 *
 * @author Administrator
 */
public class GridController {
    float w=1;
    float h=1;
    int wC=2;
    int hC=2;
    int indices[];
    int indiEW[][];
    Random r=new Random();
    ArrayList<Vector3f> al=new ArrayList<Vector3f>();
    Vector3f val[];
    float[] colorArray;
    public GridController(float w,float h,int wC,int hC){
        this.w=w;
        this.h=h;
        this.wC=wC;
        this.hC=hC;
        val=new Vector3f[hC*wC];
        indices=new int[(wC-1)*6*(hC-1)];
        indiEW=new int[(wC-1)*(hC-1)][6];
        colorArray = new float[wC*hC*4];
    }
    public boolean doGrid(){
        boolean flag=true;
        //////---------->wC
        //   |
        //   |
        //   hC;
        al.clear();
        for(int i=0;i<wC;i++){
            for(int j=0;j<hC;j++){
                float x=w*i*1.0f/wC;
                float y= 2*FastMath.sin(j*1.0f/hC*10)+2*FastMath.cos(i*1.0f/wC*15);
                float z=h*-j*1.0f/hC;
                Vector3f v=new Vector3f(x,y,z);
                al.add(v);
                val[j+i*hC]=v;
                if(y>=-4&&y<=-3.5){
                    colorArray[(j+i*hC)*4]=1.0f/255.0f;
                    colorArray[(j+i*hC)*4+1]=1.0f/255.0f;
                    colorArray[(j+i*hC)*4+2]=1.0f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }else if(y>-3.5&&y<=-3.0){
                    colorArray[(j+i*hC)*4]=20.0f/255.0f;
                    colorArray[(j+i*hC)*4+1]=20.0f/255.0f;
                    colorArray[(j+i*hC)*4+2]=20.0f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }else if(y>-3.0&&y<=-2.5){
                    colorArray[(j+i*hC)*4]=40.0f/255.0f;
                    colorArray[(j+i*hC)*4+1]=40.0f/255.0f;
                    colorArray[(j+i*hC)*4+2]=40.0f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }else if(y>-2.5&&y<=-2.0){
                    colorArray[(j+i*hC)*4]=60.0f/255.0f;
                    colorArray[(j+i*hC)*4+1]=60.0f/255.0f;
                    colorArray[(j+i*hC)*4+2]=60.0f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }else if(y>-2.0&&y<=-1.5){
                    colorArray[(j+i*hC)*4]=80.0f/255.0f;
                    colorArray[(j+i*hC)*4+1]=80.0f/255.0f;
                    colorArray[(j+i*hC)*4+2]=80.0f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }else if(y>-1.5&&y<=-1.0){
                    colorArray[(j+i*hC)*4]=100.0f/255.0f;
                    colorArray[(j+i*hC)*4+1]=100.0f/255.0f;
                    colorArray[(j+i*hC)*4+2]=100.0f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }else if(y>-1.0&&y<=0){
                    colorArray[(j+i*hC)*4]=120.0f/255.0f;
                    colorArray[(j+i*hC)*4+1]=120.0f/255.0f;
                    colorArray[(j+i*hC)*4+2]=120.0f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }else if(y>0&&y<=0.5){
                    colorArray[(j+i*hC)*4]=140.0f/255.0f;
                    colorArray[(j+i*hC)*4+1]=140.0f/255.0f;
                    colorArray[(j+i*hC)*4+2]=140.0f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }else if(y>0.5&&y<=1.0){
                    colorArray[(j+i*hC)*4]=160.0f/255.0f;
                    colorArray[(j+i*hC)*4+1]=160.0f/255.0f;
                    colorArray[(j+i*hC)*4+2]=160.0f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }
                else if(y>1.0&&y<=1.5){
                    colorArray[(j+i*hC)*4]=180.0f/255.0f;
                    colorArray[(j+i*hC)*4+1]=180.0f/255.0f;
                    colorArray[(j+i*hC)*4+2]=180.0f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }else if(y>1.5&&y<=2.0){
                    colorArray[(j+i*hC)*4]=200.0f/255.0f;
                    colorArray[(j+i*hC)*4+1]=200.0f/255.0f;
                    colorArray[(j+i*hC)*4+2]=200.0f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }else if(y>2.0&&y<=2.5){
                    colorArray[(j+i*hC)*4]=220f/255.0f;
                    colorArray[(j+i*hC)*4+1]=220.0f/255.0f;
                    colorArray[(j+i*hC)*4+2]=220.0f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }else if(y>2.5&&y<=3.0){
                    colorArray[(j+i*hC)*4]=240f/255.0f;
                    colorArray[(j+i*hC)*4+1]=240.0f/255.0f;
                    colorArray[(j+i*hC)*4+2]=240f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }else if(y>3.0&&y<=3.5){
                    colorArray[(j+i*hC)*4]=245f/255.0f;
                    colorArray[(j+i*hC)*4+1]=245f/255.0f;
                    colorArray[(j+i*hC)*4+2]=245f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }else if(y>3.5){
                    colorArray[(j+i*hC)*4]=255.0f/255.0f;
                    colorArray[(j+i*hC)*4+1]=255.0f/255.0f;
                    colorArray[(j+i*hC)*4+2]=255.0f/255.0f;
                    colorArray[(j+i*hC)*4+3]=1.0f;
                }
                
                
            }
        } 
        //System.out.println("总共有多少各项两"+val.length);
        
        
        for(int i=0;i<wC-1;i++){
            for(int j=0;j<hC-1;j++){
                indiEW[j+i*(hC-1)][0]=j+i*hC;
                indiEW[j+i*(hC-1)][1]=j+1+hC+i*hC;
                indiEW[j+i*(hC-1)][2]=j+1+i*hC;
                indiEW[j+i*(hC-1)][3]=j+i*hC;
                indiEW[j+i*(hC-1)][4]=j+hC+i*hC;
                indiEW[j+i*(hC-1)][5]=j+1+hC+i*hC;
            }
        }
        for(int i=0;i<indiEW.length;i++){
            
            indices[i*6]=indiEW[i][0];
            indices[i*6+1]=indiEW[i][1];
            indices[i*6+2]=indiEW[i][2];
            indices[i*6+3]=indiEW[i][3];
            indices[i*6+4]=indiEW[i][4];
            indices[i*6+5]=indiEW[i][5];
            
            //System.out.println(indiEW[i][0]+"  "+indiEW[i][1]+"   "+indiEW[i][2]+"   "+indiEW[i][3]+"  "+indiEW[i][4]+"   "+indiEW[i][5]);
        }
        for (int i = 0; i < val.length; i++) {
            //System.out.println("一维"+val[i]);
        }
        
        return flag;
    }

    
    
    public ArrayList<Vector3f> getAl() {
        return al;
    }

    public void setAl(ArrayList<Vector3f> al) {
        this.al = al;
    }

    public Vector3f[] getVal() {
        return val;
    }

    public void setVal(Vector3f[] val) {
        this.val = val;
    }

    public int[] getIndices() {
        return indices;
    }

    public void setIndices(int[] indices) {
        this.indices = indices;
    }

    public float[] getColorArray() {
        return colorArray;
    }
    
}
